package com.bci.internal.engine.bcibpmengine.listener;


import com.bci.internal.engine.bcibpmengine.utils.ConstantUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;

/**
 * 多实例监听
 *
 * @author jzwu
 * @since 2021/3/25 0025
 */
public class MultInstancesStartListener1 implements ExecutionListener {
    private static final Logger LOGGER = LoggerFactory.getLogger(MultInstancesStartListener1.class);

    @Override
    public void notify(DelegateExecution execution) {
        Map<String, Object> variables = execution.getVariables();
        /* 获取节点名称 */
        String nodeName = (String) variables.get(ConstantUtils.NODE_NAME);
//        String isPass = (String) variables.get(ConstantUtils.IS_PASS);
        /* 获取会签处理人 */
//        List<String> assigneeDirectorList = (List<String>) variables.get(ConstantUtils.ASSIGNEE_DIRECTOR_LIST);
//        switch (nodeName) {
//            /* 自评节点 */
//            case ConstantUtils.SELF_COMMENT:/*
//                Map<String, Object> mapVaribales = new HashMap<>();
//
//                ArrayList<String> assigneeDirectorList = new ArrayList<>();
//                assigneeDirectorList.add("wukong");
//                assigneeDirectorList.add("tangshen");
//
////        execution.setVariable("assigneeDirectorList",assigneeDirectorList);
//                mapVaribales.put("assigneeDirectorList", assigneeDirectorList);
//                mapVaribales.put("number", assigneeDirectorList.size());
//                execution.setVariables(mapVaribales);*/
//
//           /*     Map<String, Object> mapVaribales = new HashMap<>();
//                mapVaribales.put(ConstantUtils.ASSIGNEE_DIRECTOR_LIST, assigneeDirectorList);
//                mapVaribales.put(ConstantUtils.NUMBER, assigneeDirectorList.size());
//                execution.setVariables(mapVaribales);*/
//                break;
//            /* 总监评分节点 */
//            case ConstantUtils.DIRTOR:
//                /* 如果isPass==1 则将会签任务强制结束 */
//                /*if (Objects.equals(isPass, 1)) {
//                    Integer complete = (Integer) execution.getParent().getVariable("nrOfCompletedInstances");
//                    LOGGER.info("complete = {}", complete);
//                    Integer all = (Integer) execution.getParent().getVariable("nrOfInstances");
//                    LOGGER.info("all = {}", all);
//                    execution.setVariable("nrOfCompletedInstances", complete);
//                }*/
//                break;
//            default:
//                break;
//        }


/*        mapVaribales.put("directorPass", 2);
        mapVaribales.put("isPass", 0);*/
//        mapVaribales.put("isPass",0);
//        execution.setVariables(mapVaribales);
//        execution.setVariable("isPass", 0);
//        execution.setVariable("assigneeSelf","bajie");

        //execution.setVariable("isPass",0);
   /*     Integer directorPass = (Integer) execution.getVariable("directorPass");
        LOGGER.info("directorPass= {}", directorPass);
        Integer complete = (Integer) execution.getParent().getVariable("nrOfCompletedInstances");
        LOGGER.info("complete = {}", complete);
        Integer all = (Integer) execution.getParent().getVariable("nrOfInstances");
        LOGGER.info("all = {}", all);*/
//        execution.setVariable("nrOfCompletedInstances", assigneeDirectorList.size());
    }
}